package com.wonders.cyxtjsonupdate.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.wonders.cyxtjsonupdate.entity.Cyxt;
import com.wonders.cyxtjsonupdate.service.CyxtJsonData;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.*;

/**
 * @Description:
 * @ClassName: CyxtJsonUtil
 * @Author: 陈兆庆
 * @Date: 2022/1/10 17:12
 * @Version: 1.0     // 版本
 */
public class CyxtJsonUtil {
    @Autowired
    static CyxtJsonData cyxtJsonData;

    public List test1() {
        Calendar cal = Calendar.getInstance();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(0);//保留0位
        ArrayList<String> list = new ArrayList<>();//用来存储所有的最终的json
        //初始化全社会货物运输量
        List<Map<String, Object>> init = cyxtJsonData.init();
        //初始化公路货物运输量
        List<Map<String, Object>> roadTransportList = cyxtJsonData.initRoadTransport();
        //初始化水路货物运输量
        List<Map<String, Object>> waterWayList = cyxtJsonData.initWaterWayTransport();
        //初始化铁路货物运输量
        List<Map<String, Object>> railwayList = cyxtJsonData.initrailwayTransport();
        //初始化航空货物运输量
        List<Map<String, Object>> airList = cyxtJsonData.initairTransport();
        //初始化全港货物吞吐量
        List<Map<String, Object>> harborList = cyxtJsonData.initHarborThroughput();
        //初始化两个饼图海港累计吞吐量
        List<Map<String, Object>> seaborList = cyxtJsonData.initHarborPieChart();
        //初始化两个饼图内河港累计吞吐量
        List<Map<String, Object>> harborRiverList = cyxtJsonData.initRiverPieChart();
        //初始化两个饼图外贸累计吞吐量
        List<Map<String, Object>> foreignTradeList = cyxtJsonData.initForeignTrade();
        //初始化两个饼图内贸累计吞吐量
        List<Map<String, Object>> domesticTradeList = cyxtJsonData.initDomesticTrade();
        //初始化集装箱吞吐量
        List<Map<String, Object>> containerList = cyxtJsonData.initcontainer();
        //初始化洋山深水港区完成量
        List<Map<String, Object>> ssgqList = cyxtJsonData.initcontainerysssgq();


        //获得当前月份
        int month = new Date().getMonth();
        month = 11;//因目前1月份数据库未产生12月份数据，此此先模拟
        //获得当前年份
        int year = cal.get(Calendar.YEAR);

        //----全社会货物运输量、百分比的Map
        Cyxt cyxt1 = buildgeneralpParame("40a573341be84eb9af601d359da70947", "hyLazy", "yqshhwysl");
        Map<String, Object> stringObjectMap = init.get(month - 1);
        //月均
        buildfreightMonthAverage(cyxt1, month, stringObjectMap, list, nf);

        //同比增长
        Cyxt cyxt2 = buildgeneralpParame("faf1139827b24c7ea576582a1255daaf", "hyLazy", "yqshhwyslbfb");
        buildfreightYearGrowth(cyxt2, stringObjectMap, list);

        //--累计（yearSum）
        Cyxt cyxt3 = buildgeneralpParame("93c6065815514ec7bac1bf936193a853", "hyLazy", "bqshhwysl");
        buildfreightYeartotal(cyxt3, stringObjectMap, list, nf);

        //-- 同比增量（BNBSNTQZJB字段）
        Cyxt cyxt4 = buildgeneralpParame("5a819d0ff78e4603a3cc5b92c3c2b8b5", "hyLazy", "bqshhwyslbfb");
        buildfreightYeartoYeartotal(cyxt4, stringObjectMap, list);


        //----公路货物运输量、百分比的Map
        Map<String, Object> roadMap = roadTransportList.get(month - 1);
        Cyxt cyxt5 = buildgeneralpParame("a26c97630ab24cf988a1c0fbb2f57b04", "hyLazy", "yglhwysl");
        //月均
        buildfreightMonthAverage(cyxt5, month, roadMap, list, nf);

        //同比增长
        Cyxt cyxt6 = buildgeneralpParame("febb46d9943d42dbb4cbb5efb9258dc2", "hyLazy", "yglhwyslbfb");
        buildfreightYearGrowth(cyxt6, roadMap, list);

        //累计
        Cyxt cyxt7 = buildgeneralpParame("ed4eca7dd3db4b349d61a1e26fbd6765", "hyLazy", "bglhwysl");
        buildfreightYeartotal(cyxt7, roadMap, list, nf);

        //-- 同比增量（BNBSNTQZJB字段）
        Cyxt cyxt8 = buildgeneralpParame("ab6395b4c58044c18eb23c2b98f0ea29", "hyLazy", "bglhwyslbfb");
        buildfreightYeartoYeartotal(cyxt8, roadMap, list);

        //----水路货物运输量、百分比的Map
        Map<String, Object> waterMap = waterWayList.get(month - 1);
        Cyxt cyxt9 = buildgeneralpParame("a605d3a5a4384453b78db1522e0fae44", "hyLazy", "yslhwysl");
        //--月均
        buildfreightMonthAverage(cyxt9, month, waterMap, list, nf);

        //同比增长
        Cyxt cyxt10 = buildgeneralpParame("dda8e840e5024ac28b80125484c689a6", "hyLazy", "yslhwyslbfb");
        buildfreightYearGrowth(cyxt10, waterMap, list);

        //--累计
        Cyxt cyxt11 = buildgeneralpParame("93c6065815514ec7bac1bf936193a853", "hyLazy", "bqshhwysl");
        buildfreightYeartotal(cyxt11, waterMap, list, nf);

        //-- 同比增量（BNBSNTQZJB字段）
        Cyxt cyxt12 = buildgeneralpParame("ab6395b4c58044c18eb23c2b98f0ea29", "hyLazy", "bglhwyslbfb");
        buildfreightYeartoYeartotal(cyxt12, waterMap, list);

        //----铁路货物运输量、百分比的Map
        Map<String, Object> railwayMap = railwayList.get(month - 1);
        //--月均
        Cyxt cyxt13 = buildgeneralpParame("676408728cc643dbb03f84502348e76d", "hyLazy", "ytlhwysl");
        buildfreightMonthAverage(cyxt13, month, railwayMap, list, nf);

        //同比增长
        Cyxt cyxt14 = buildgeneralpParame("4846a35d3c704f48b3e0f8e358507270", "hyLazy", "ytlhwyslbfb");
        buildfreightYearGrowth(cyxt14, railwayMap, list);

        //--累计
        Cyxt cyxt15 = buildgeneralpParame("93c6065815514ec7bac1bf936193a853", "hyLazy", "bqshhwysl");
        buildfreightYeartotal(cyxt15, railwayMap, list, nf);

        //-- 同比增量（BNBSNTQZJB字段）
        Cyxt cyxt16 = buildgeneralpParame("a7e65588e92e4889b3fc4c97523ca092", "hyLazy", "btlhwyslbfb");
        buildfreightYearGrowth(cyxt16, railwayMap, list);

        //----航空货物运输量、百分比的Map
        Map<String, Object> airMap = airList.get(month - 1);
        //--月均
        Cyxt cyxt17 = buildgeneralpParame("8083d8da97364cc4853ae540bd940c39", "hyLazy", "yjchwttl");
        buildfreightMonthAverage(cyxt17, month, airMap, list, nf);

        //--同比增量（字段BNBSNTQZJB）
        Cyxt cyxt18 = buildgeneralpParame("b62c482499704c3b9cf3bdbd24740734", "hyLazy", "yjchwttlbfb");
        buildfreightYearGrowth(cyxt18, airMap, list);

        //--累计

        Cyxt cyxt19 = buildgeneralpParame("868c4b8e1abb4614aaeecc144e4e7d3d", "hyLazy", "bjchwttl");
        buildfreightYeartotal(cyxt19, airMap, list, nf);

        //-- 同比增量（BNBSNTQZJB字段）
        Cyxt cyxt20 = buildgeneralpParame("fdc9d3d8497d4eb0aac6708f6b9c8aca", "hyLazy", "bjchwttlbfb");
        buildfreightYearGrowth(cyxt20, airMap, list);


        //-----货物运输量月分布
        Cyxt cyxt21 = buildgeneralpParame("9ff99ab83aae4bf58c67af3023f3aec7", "hyLazy", "myChart1");
        ArrayList<List<Integer>> dataList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < month; j++) {
                if (i == 0) {
                    ArrayList<Integer> allfreightList = new ArrayList<>();
                    allfreightList.add(0);
                    allfreightList.add(j);
                    Object monthsum = airList.get(j).get("MONTHSUM");
                    BigDecimal multiply = new BigDecimal(monthsum.toString()).multiply(new BigDecimal("10000"));
                    allfreightList.add(multiply.intValue());
                    dataList.add(allfreightList);
                } else if (i == 1) {
                    ArrayList<Integer> allfreightList = new ArrayList<>();
                    allfreightList.add(1);
                    allfreightList.add(j);
                    Object monthsum = waterWayList.get(j).get("MONTHSUM");
                    BigDecimal multiply = new BigDecimal(monthsum.toString()).multiply(new BigDecimal("10000"));
                    allfreightList.add(multiply.intValue());
                    dataList.add(allfreightList);
                } else if (i == 2) {
                    ArrayList<Integer> allfreightList = new ArrayList<>();
                    allfreightList.add(2);
                    allfreightList.add(j);
                    Object monthsum = roadTransportList.get(j).get("MONTHSUM");
                    BigDecimal multiply = new BigDecimal(monthsum.toString()).multiply(new BigDecimal("10000"));
                    allfreightList.add(multiply.intValue());
                    dataList.add(allfreightList);
                } else if (i == 3) {
                    ArrayList<Integer> allfreightList = new ArrayList<>();
                    allfreightList.add(3);
                    allfreightList.add(j);
                    Object monthsum = railwayList.get(j).get("MONTHSUM");
                    BigDecimal multiply = new BigDecimal(monthsum.toString()).multiply(new BigDecimal("10000"));
                    allfreightList.add(multiply.intValue());
                    dataList.add(allfreightList);
                }
            }
        }


        //拼接月份的集合
        ArrayList<String> monthList = new ArrayList<>();

        //拼接月份
        for (int i = 0; i < month; i++) {
            if (i == 0) {
                monthList.add("'一月'");
            } else if (i == 1) {
                monthList.add("'二月'");
            } else if (i == 2) {
                monthList.add("'三月'");
            } else if (i == 3) {
                monthList.add("'四月'");
            } else if (i == 4) {
                monthList.add("'五月'");
            } else if (i == 5) {
                monthList.add("'六月'");
            } else if (i == 6) {
                monthList.add("'七月'");
            } else if (i == 7) {
                monthList.add("'八月'");
            } else if (i == 8) {
                monthList.add("'九月'");
            } else if (i == 9) {
                monthList.add("'十月'");
            } else if (i == 10) {
                monthList.add("'十一月'");
            } else if (i == 11) {
                monthList.add("'十二月'");
            }
        }
        cyxt21.setDataItem1(dataList.toString());
        cyxt21.setDataItem2("['机场', '水路', '公路', '铁路']");
        cyxt21.setDataItem3(monthList.toString().replace(" ", ""));
        String tbzz7str = JSONObject.toJSONString(cyxt21, SerializerFeature.WriteMapNullValue);
        list.add(tbzz7str);

        //--------本年日均货物运输量、去年日均货物运输量
        Cyxt cyxt22 = buildgeneralpParame("5ed7fb06e4304054a3d898538680b498", "hyLazy", "myChart6");
        cyxt22.setDataItem1("[{text: '公路', max: 2000000},{text: '水路', max: 2500000},{text: '铁路', max: 2000000},{text: '机场', max: 2000000}]");
        ArrayList<Integer> allYearAvg = new ArrayList<>();
        //公路本年日均
        BigDecimal road1 = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(roadTransportList.get(i).get("YEARAVG").toString());
            road1 = road1.add(yearavg);
        }
        road1 = road1.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        allYearAvg.add(road1.intValue());
        //水路本年日均
        BigDecimal waterWay = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(waterWayList.get(i).get("YEARAVG").toString());
            waterWay = waterWay.add(yearavg);
        }
        waterWay = waterWay.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        allYearAvg.add(waterWay.intValue());
        //铁路本年日均
        BigDecimal railWay = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(railwayList.get(i).get("YEARAVG").toString());
            railWay = railWay.add(yearavg);
        }
        railWay = railWay.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        allYearAvg.add(railWay.intValue());
        //机场本年日均
        BigDecimal airport = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(airList.get(i).get("YEARAVG").toString());
            airport = airport.add(yearavg);
        }
        airport = airport.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        allYearAvg.add(airport.intValue());

        cyxt22.setDataItem2(allYearAvg.toString());
        String tbzz8str = JSONObject.toJSONString(cyxt22, SerializerFeature.WriteMapNullValue);
        list.add(tbzz8str);

        //去年日均货物运输量
        Cyxt cyxt23 = buildgeneralpParame("ab604c15e5c94916afc70aaa4066f358", "hyLazy", "myChart7");
        cyxt23.setDataItem1("[{text: '公路', max: 2000000},{text: '水路', max: 2000000},{text: '铁路', max: 2000000},{text: '机场', max: 2000000}]");
        ArrayList<Integer> lastYearAvg = new ArrayList<>();
        //公路去年日均
        BigDecimal road2 = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(roadTransportList.get(i).get("SNTY").toString());
            if (i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9 || i == 11) {
                yearavg = yearavg.divide(new BigDecimal("31"), 0, BigDecimal.ROUND_HALF_UP);
            } else if (i == 3 || i == 5 || i == 8 || i == 10) {
                yearavg = yearavg.divide(new BigDecimal("30"), 0, BigDecimal.ROUND_HALF_UP);
            } else {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    yearavg = yearavg.divide(new BigDecimal("29"), 0, BigDecimal.ROUND_HALF_UP);
                } else {
                    yearavg = yearavg.divide(new BigDecimal("28"), 0, BigDecimal.ROUND_HALF_UP);
                }
            }
            road2 = road2.add(yearavg);
        }
        road2 = road2.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        lastYearAvg.add(road2.intValue());
        //水路去年日均
        BigDecimal waterroad = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(waterWayList.get(i).get("SNTY").toString());
            if (i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9 || i == 11) {
                yearavg = yearavg.divide(new BigDecimal("31"), 0, BigDecimal.ROUND_HALF_UP);
            } else if (i == 3 || i == 5 || i == 8 || i == 10) {
                yearavg = yearavg.divide(new BigDecimal("30"), 0, BigDecimal.ROUND_HALF_UP);
            } else {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    yearavg = yearavg.divide(new BigDecimal("29"), 0, BigDecimal.ROUND_HALF_UP);
                } else {
                    yearavg = yearavg.divide(new BigDecimal("28"), 0, BigDecimal.ROUND_HALF_UP);
                }
            }
            waterroad = waterroad.add(yearavg);
        }
        waterroad = waterroad.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        lastYearAvg.add(waterroad.intValue());
        //铁路去年日均
        BigDecimal railwayrood = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(railwayList.get(i).get("SNTY").toString());
            if (i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9 || i == 11) {
                yearavg = yearavg.divide(new BigDecimal("31"), 0, BigDecimal.ROUND_HALF_UP);
            } else if (i == 3 || i == 5 || i == 8 || i == 10) {
                yearavg = yearavg.divide(new BigDecimal("30"), 0, BigDecimal.ROUND_HALF_UP);
            } else {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    yearavg = yearavg.divide(new BigDecimal("29"), 0, BigDecimal.ROUND_HALF_UP);
                } else {
                    yearavg = yearavg.divide(new BigDecimal("28"), 0, BigDecimal.ROUND_HALF_UP);
                }
            }
            railwayrood = railwayrood.add(yearavg);
        }
        railwayrood = railwayrood.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        lastYearAvg.add(railwayrood.intValue());
        //航空去年日均
        BigDecimal air = new BigDecimal("0");
        for (int i = 0; i < month; i++) {
            BigDecimal yearavg = new BigDecimal(airList.get(i).get("SNTY").toString());
            if (i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9 || i == 11) {
                yearavg = yearavg.divide(new BigDecimal("31"), 0, BigDecimal.ROUND_HALF_UP);
            } else if (i == 3 || i == 5 || i == 8 || i == 10) {
                yearavg = yearavg.divide(new BigDecimal("30"), 0, BigDecimal.ROUND_HALF_UP);
            } else {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    yearavg = yearavg.divide(new BigDecimal("29"), 0, BigDecimal.ROUND_HALF_UP);
                } else {
                    yearavg = yearavg.divide(new BigDecimal("28"), 0, BigDecimal.ROUND_HALF_UP);
                }
            }
            air = air.add(yearavg);
        }
        air = air.multiply(new BigDecimal("10000")).divide(new BigDecimal(month + ""), 0, BigDecimal.ROUND_HALF_UP);
        lastYearAvg.add(air.intValue());
        cyxt23.setDataItem2(lastYearAvg.toString());
        String tbzz9str = JSONObject.toJSONString(cyxt23, SerializerFeature.WriteMapNullValue);
        list.add(tbzz9str);


        //----------四个折线图(月趋势)
        //----公路
        buildChart("18cd93cffe534f1e8f70092f766db0ca", "hyLazy", "myChart2", month, "MONTHSUM", "SNTY", monthList, roadTransportList, list);
        //-----水路
        buildChart("17ef6746ac9e4fcda26f77d2db4f565f", "hyLazy", "myChart3", month, "MONTHSUM", "SNTY", monthList, waterWayList, list);
        //----铁路
        buildChart("9a9ebead0308426eb75cfacafc774995", "hyLazy", "myChart4", month, "MONTHSUM", "SNTY", monthList, railwayList, list);
        //----机场
        buildChart("fc8d111441844c4cae11005e795d359d", "hyLazy", "myChart5", month, "MONTHSUM", "SNTY", monthList, airList, list);
        //全港货物吞吐量
        buildHarborThroughput(month, harborList, list, nf);
        //---------两个饼图海河港内外贸累计吞吐量
        buildPieHarborAndTrading(month, seaborList, harborRiverList, foreignTradeList, domesticTradeList, list);
        //本年度【海河港】、上年度【海河港】月趋势
        harbortrend(month, seaborList, harborRiverList, list);
        //本年度【内外贸】、上年度【内外贸】月趋势
        domesticAndforeigntrade(month, foreignTradeList, domesticTradeList, list);
        //集装箱吞吐量、同比
        containerThroughput(month, containerList, list, nf);
        //集装箱【本年度/上年度】货运量月趋势
        buildcontainerTrend(month, containerList, list);
        //月均洋山深水港区完成量
        bulidcontaineryyssgq(month, ssgqList, list, nf);
        //洋山深水港月完成量趋势
        buildyshsMonthlyTrend(month, ssgqList, list);
        //洋山深水港吞吐总量占比月趋势
        buildTotalThroughputMonthlyTrendofpProportion(month, ssgqList, containerList, list);
        return list;
    }


    /**
     * Methad info:货物运输量------月均
     *
     * @author 陈兆庆
     * @date 2022/1/5 11:23
     */
    public static void buildfreightMonthAverage(Cyxt cyxt, int month, Map<String, Object> dataMap, List list, NumberFormat nf) {
        //月均
        Object yearsum = dataMap.get("YEARSUM");
        double yearsumd = Double.parseDouble(yearsum.toString());
        double monthavg = yearsumd / month * 10000;
        String format = nf.format(monthavg);
        cyxt.setDataItem1(format);
        String yjhy = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(yjhy);
    }

    /**
     * Methad info:货物运输量------同比增长
     *
     * @author 陈兆庆
     * @date 2022/1/5 14:09
     */

    public static void buildfreightYearGrowth(Cyxt cyxt, Map<String, Object> dataMap, List list) {
        Object bnbsntqzjb = dataMap.get("BNBSNTQZJB");
        cyxt.setDataItem1(bnbsntqzjb + "%");
        String tbzz = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(tbzz);
    }

    /**
     * Methad info:货物运输量------累计
     *
     * @author 陈兆庆
     * @date 2022/1/5 14:12
     */

    public static void buildfreightYeartotal(Cyxt cyxt, Map<String, Object> dataMap, List list, NumberFormat nf) {
        //--累计（yearSum）
        Object yearsum = dataMap.get("YEARSUM");
        double yearsum1 = Double.parseDouble(yearsum.toString()) * 10000;
        String format1 = nf.format(yearsum1);
        cyxt.setDataItem1(format1);
        String lj = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(lj);
    }

    /**
     * Methad info:货物运输量------同比增量
     *
     * @author 陈兆庆
     * @date 2022/1/5 14:15
     */

    public static void buildfreightYeartoYeartotal(Cyxt cyxt, Map<String, Object> dataMap, List list) {
        //-- 同比增量（BNBSNTQZJB字段）
        Object tbzz = dataMap.get("BNBSNTQZJB");
        cyxt.setDataItem1(tbzz + "%");
        String tbzz2str = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(tbzz2str);
    }


    /**
     * Methad info:四个折线图(月趋势)
     *
     * @author 陈兆庆
     * @date 2022/1/4 13:36
     */
    public static void buildChart(String id, String mainType, String subType, int month, String keys, String snty, List monthList, List<Map<String, Object>> listdata, List list) {
        Cyxt cyxt = new Cyxt();
        cyxt.setId(id);
        cyxt.setMainType(mainType);
        cyxt.setSubType(subType);
        cyxt.setDataItem1(monthList.toString().replace(" ", ""));
        ArrayList<Integer> roadChart1 = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = listdata.get(i).get(keys);
            /*     Integer ceil = (int)Math.ceil(Double.valueOf(monthsum.toString()))*10000;//此处数据有差异，后续确认是否向上取整*/
            double ceila = Double.parseDouble(monthsum.toString());
            int ceil = (int) (ceila * 10000);
            roadChart1.add(ceil);
        }
        //去年月总
        ArrayList<Integer> roadChart2 = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = listdata.get(i).get(snty);
            /*       Integer ceil = (int)Math.ceil(Double.valueOf(monthsum.toString()))*10000;//此处数据有差异，后续确认是否向上取整*/
            double ceila = Double.parseDouble(monthsum.toString());
            int ceil = (int) (ceila * 10000);
            roadChart2.add(ceil);
        }
        cyxt.setDataItem2(roadChart1.toString().replace(" ", ""));
        cyxt.setDataItem3(roadChart2.toString().replace(" ", ""));
        String tbzz10str = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(tbzz10str);
    }

    /**
     * Methad info:全港货物吞吐量、同比
     *
     * @author 陈兆庆
     * @date 2022/1/4 13:39
     */
    public static void buildHarborThroughput(int month, List<Map<String, Object>> listdata, List list, NumberFormat nf) {
        Cyxt cyxt = buildgeneralpParame("ccfbc0440da34871bb7322e040a5aeb6", "hyLazy", "bnqghwttl");
        Object yearsumo = listdata.get(month - 1).get("YEARSUM");
        double yearsumd = Double.parseDouble(yearsumo.toString()) * 10000;
        String format = nf.format(yearsumd);
        cyxt.setDataItem1(format);
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
        Cyxt cyxt1 = buildgeneralpParame("d0e047accbc04b0fa95b12a7efb8166b", "hyLazy", "bnqghwttlbfb");
        Object bnbsntqzjb = listdata.get(month - 1).get("BNBSNTQZJB");
        cyxt1.setDataItem1("本年月均全港货物吞吐量(吨)&nbsp;&nbsp;" + bnbsntqzjb + "%");
        String data1 = JSONObject.toJSONString(cyxt1, SerializerFeature.WriteMapNullValue);
        list.add(data1);
        //-------全港货物月均吞吐量、同比
        Cyxt cyxt2 = buildgeneralpParame("c3c85f93f82e4b859d90361bcb4a6e05", "hyLazy", "bnyjqghwttl");
        double harbormonth = (int) (yearsumd / month);
        String qghwyjttl = nf.format(harbormonth);
        cyxt2.setDataItem1(qghwyjttl);
        String data2 = JSONObject.toJSONString(cyxt2, SerializerFeature.WriteMapNullValue);
        list.add(data2);
        Cyxt cyxt3 = buildgeneralpParame("65f55ad74aa0487dbd3befcfeaa05b8f", "hyLazy", "bnyjqghwttlbfb");
        cyxt3.setDataItem1("本年月均全港货物吞吐量(吨)&nbsp;&nbsp;" + bnbsntqzjb + "%");
        String data3 = JSONObject.toJSONString(cyxt3, SerializerFeature.WriteMapNullValue);
        list.add(data3);
        //-------全港货物吞吐量月趋势【本年、上年】
        Cyxt cyxt4 = buildgeneralpParame("c9d1810011024f409861987dd357ab1e", "hyLazy", "myChart8");
        List monthList = buildMonth(month);
        cyxt4.setDataItem1(monthList.toString().replace(" ", ""));
        ArrayList<Integer> yearList1 = new ArrayList<>();//今年
        for (int i = 0; i < month; i++) {
            Object yearsum = listdata.get(i).get("MONTHSUM");
            int yeartosum = (int) (Double.parseDouble(yearsum.toString()) * 10000);
            yearList1.add(yeartosum);
        }
        cyxt4.setDataItem2(yearList1.toString().replace(" ", ""));
        ArrayList<Integer> yearList2 = new ArrayList<>();//去年
        for (int i = 0; i < month; i++) {
            Object yearsum = listdata.get(i).get("SNTY");
            int yeartosum = (int) (Double.parseDouble(yearsum.toString()) * 10000);
            yearList2.add(yeartosum);
        }
        cyxt4.setDataItem3(yearList2.toString().replace(" ", ""));
        String data4 = JSONObject.toJSONString(cyxt4, SerializerFeature.WriteMapNullValue);
        list.add(data4);
    }


    /**
     * Methad info:两个饼图（海河港、内外贸）累计吞吐量
     *
     * @author 陈兆庆
     * @date 2022/1/4 15:23
     */

    public static void buildPieHarborAndTrading(int month, List<Map<String, Object>> seaborList, List<Map<String, Object>> harborRiverList, List<Map<String, Object>> foreignTradeList, List<Map<String, Object>> domesticTradeList, List list) {
        //河海港
        Cyxt cyxt = buildgeneralpParame("40029256468f437fbc9f5f818e0afd20", "hyLazy", "myChart9");
        Object yearsumSea = seaborList.get(month - 1).get("YEARSUM");
        Object yearsumRiver = harborRiverList.get(month - 1).get("YEARSUM");
        //海港年累计
        int yearsum1 = (int) (Double.parseDouble(yearsumSea.toString()) * 10000);
        //内河港年累计
        int yearsum2 = (int) (Double.parseDouble(yearsumRiver.toString()) * 10000);
        cyxt.setDataItem1("[{value: " + yearsum1 + ",name: '海港'},{value: " + yearsum2 + ", name: '内河港'}]");
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
        //内外贸
        Cyxt cyxt1 = buildgeneralpParame("78367b7bf3294f9582693c29c45753e6", "hyLazy", "myChart10");
        Object foreignTrade = foreignTradeList.get(month - 1).get("YEARSUM");
        Object domesticTrade = domesticTradeList.get(month - 1).get("YEARSUM");
        //外贸年累计
        int foreignTradeSum = (int) (Double.parseDouble(foreignTrade.toString()) * 10000);
        //内贸年累计
        int domesticTradeSum = (int) (Double.parseDouble(domesticTrade.toString()) * 10000);
        cyxt1.setDataItem1("[{value: " + foreignTradeSum + ",name: '外贸'},{value: " + domesticTradeSum + ", name: '内贸'}]");
        String data1 = JSONObject.toJSONString(cyxt1, SerializerFeature.WriteMapNullValue);
        list.add(data1);
    }

    /**
     * Methad info:本年度【海河港】、上年度【海河港】月趋势
     *
     * @author 陈兆庆
     * @date 2022/1/4 16:11
     */

    public static void harbortrend(int month, List<Map<String, Object>> seaborList, List<Map<String, Object>> harborRiverList, List list) {
        Cyxt cyxt = buildgeneralpParame("e58cfcff2a384117939c848dc8530c89", "hyLazy", "myChart12");
        List monthList = buildMonth(month);
        cyxt.setDataItem1(monthList.toString().replace(" ", ""));
        //本年度海港
        ArrayList<Integer> seaPortofthisyear = new ArrayList<>();
        //上年度海港
        ArrayList<Integer> seaPortoflastyear = new ArrayList<>();
        //本年度内河港
        ArrayList<Integer> riverPortofthisyear = new ArrayList<>();
        //上年度内河港
        ArrayList<Integer> riverPortoflastyear = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = seaborList.get(i).get("MONTHSUM");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            seaPortofthisyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = seaborList.get(i).get("SNTY");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            seaPortoflastyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = harborRiverList.get(i).get("MONTHSUM");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            riverPortofthisyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = harborRiverList.get(i).get("SNTY");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            riverPortoflastyear.add(yearsum1);
        }
        cyxt.setDataItem2(seaPortofthisyear.toString().replace(" ", ""));
        cyxt.setDataItem3(riverPortofthisyear.toString().replace(" ", ""));
        cyxt.setDataItem4(seaPortoflastyear.toString().replace(" ", ""));
        cyxt.setDataItem5(riverPortoflastyear.toString().replace(" ", ""));
        String data1 = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data1);
    }

    /**
     * Methad info:本年度【内外贸】、上年度【内外贸】月趋势
     *
     * @author 陈兆庆
     * @date 2022/1/4 16:11
     */

    public static void domesticAndforeigntrade(int month, List<Map<String, Object>> foreignTradeList, List<Map<String, Object>> domesticTradeList, List list) {
        Cyxt cyxt = buildgeneralpParame("b83030edd04b4ab9ac923103e232e95b", "hyLazy", "myChart13");
        List monthList = buildMonth(month);
        //拼接月份
        cyxt.setDataItem1(monthList.toString().replace(" ", ""));
        //本年度内贸
        ArrayList<Integer> domestictradethisyear = new ArrayList<>();
        //本年度外贸
        ArrayList<Integer> foreigntradethisyear = new ArrayList<>();
        //上年度内贸
        ArrayList<Integer> domestictradelastyear = new ArrayList<>();
        //上年度外贸
        ArrayList<Integer> foreigntradelastyear = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = domesticTradeList.get(i).get("MONTHSUM");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            domestictradethisyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = domesticTradeList.get(i).get("SNTY");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            domestictradelastyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = foreignTradeList.get(i).get("MONTHSUM");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            foreigntradethisyear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = foreignTradeList.get(i).get("SNTY");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            foreigntradelastyear.add(yearsum1);
        }
        cyxt.setDataItem2(domestictradethisyear.toString().replace(" ", ""));
        cyxt.setDataItem3(foreigntradethisyear.toString().replace(" ", ""));
        cyxt.setDataItem4(domestictradelastyear.toString().replace(" ", ""));
        cyxt.setDataItem5(foreigntradelastyear.toString().replace(" ", ""));
        String data1 = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data1);
    }

    /**
     * Methad info:集装箱月均吞吐量、同比
     *
     * @author 陈兆庆
     * @date 2022/1/4 17:33
     */

    public static void containerThroughput(int month, List<Map<String, Object>> containerList, List list, NumberFormat nf) {
        Cyxt cyxt = buildgeneralpParame("3e8e31dd847541668cb540407b0b492f", "hyLazy", "bnjzxttl");
        Object yearsum = containerList.get(month - 1).get("YEARSUM");
        double yearsum1 = Double.parseDouble(yearsum.toString()) * 10000;
        String format1 = nf.format(yearsum1);
        cyxt.setDataItem1(format1);
        String data1 = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data1);
        Cyxt cyxt1 = buildgeneralpParame("12eb3ed1d8de455aa2b46a3430aa516b", "hyLazy", "bnjzxttlbfb");
        Object tb = containerList.get(month - 1).get("BNBSNTQZJB");
        cyxt1.setDataItem1("本年集装箱吞吐量(TUE)&nbsp;&nbsp;" + tb + "%");
        String data2 = JSONObject.toJSONString(cyxt1, SerializerFeature.WriteMapNullValue);
        list.add(data2);
        Cyxt cyxt2 = buildgeneralpParame("64d8ba8bf0e34b41a3111d37586f6614", "hyLazy", "bnyjjzxttl");
        double monthAvg = (int) yearsum1 / month;
        String monthAvgstr = nf.format(monthAvg);
        cyxt2.setDataItem1(monthAvgstr);
        String data3 = JSONObject.toJSONString(cyxt2, SerializerFeature.WriteMapNullValue);
        list.add(data3);
        Cyxt cyxt3 = buildgeneralpParame("06f69189cec141f0977336a0a4b8f6a1", "hyLazy", "bnyjjzxttlbfb");
        cyxt3.setDataItem1("本年月均集装箱吞吐量(TUE)  " + tb + "%");
        String data4 = JSONObject.toJSONString(cyxt3, SerializerFeature.WriteMapNullValue);
        list.add(data4);
    }

    /**
     * Methad info:集装箱【本年度/上年度】货运量月趋势
     *
     * @author 陈兆庆
     * @date 2022/1/4 17:34
     */
    public static void buildcontainerTrend(int month, List<Map<String, Object>> containerList, List list) {
        Cyxt cyxt = buildgeneralpParame("6c57021c6a8147f88a3ec9ecf5ed3d82", "hyLazy", "myChart15");
        List monthList = buildMonth(month);
        cyxt.setDataItem1(monthList.toString().replace(" ", ""));
        //本年度货运量
        ArrayList<Integer> containerthisList = new ArrayList<>();
        //上年度货运量
        ArrayList<Integer> containerlastList = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = containerList.get(i).get("MONTHSUM");
            int monSum = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            containerthisList.add(monSum);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = containerList.get(i).get("SNTY");
            int monSum = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            containerlastList.add(monSum);
        }
        cyxt.setDataItem2(containerthisList.toString().replace(" ", ""));
        cyxt.setDataItem3(containerlastList.toString().replace(" ", ""));
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
    }

    /**
     * Methad info:月均洋山深水港区完成量和累计洋山深水港完成量
     *
     * @author 陈兆庆
     * @date 2022/1/4 17:58
     */

    public static void bulidcontaineryyssgq(int month, List<Map<String, Object>> ssgqList, List list, NumberFormat nf) {
        Cyxt cyxt = buildgeneralpParame("e31343f5310f4f859a5a2567e5298e64", "hyLazy", "bnyjysssg");
        Object yearsum = ssgqList.get(month - 1).get("YEARSUM");
        double yearsum1 = (int) Double.parseDouble(yearsum.toString()) * 10000 / month;
        String format1 = nf.format(yearsum1);
        cyxt.setDataItem1(format1);
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
        Cyxt cyxt1 = buildgeneralpParame("72599e47cc1b4bc9be8790d1c55f3f59", "hyLazy", "bnyjysssgbfb");
        Object ttzz = ssgqList.get(month - 1).get("BNBSNTQZJB");
        cyxt1.setDataItem1("&nbsp;&nbsp;" + ttzz + "%");
        String data1 = JSONObject.toJSONString(cyxt1, SerializerFeature.WriteMapNullValue);
        list.add(data1);
        Cyxt cyxt2 = buildgeneralpParame("e8b8bfbc0fee4bec8eccb8328a08bd5b", "hyLazy", "bnljysssg");
        double yearsum2 = (int) Double.parseDouble(yearsum.toString()) * 10000;
        cyxt2.setDataItem1(nf.format(yearsum2));
        String data2 = JSONObject.toJSONString(cyxt2, SerializerFeature.WriteMapNullValue);
        list.add(data2);
        Cyxt cyxt3 = buildgeneralpParame("0bd2c7ff14df4411adb1618205ee4ede", "hyLazy", "bnljysssgbfb");
        cyxt3.setDataItem1("&nbsp;&nbsp;" + ttzz + "%");
        String data4 = JSONObject.toJSONString(cyxt3, SerializerFeature.WriteMapNullValue);
        list.add(data4);
    }

    /**
     * Methad info:洋山深水港月完成量趋势(TEU)
     *
     * @author 陈兆庆
     * @date 2022/1/5 10:26
     */

    public static void buildyshsMonthlyTrend(int month, List<Map<String, Object>> ssgqList, List list) {
        Cyxt cyxt = buildgeneralpParame("a4e2db1267f142adb79d0706f0ca0e9b", "hyLazy", "myChart19");
        cyxt.setDataItem1(buildMonth(month).toString().replace(" ", ""));
        ArrayList<Integer> thisYear = new ArrayList<>();
        ArrayList<Integer> lastYear = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsum = ssgqList.get(i).get("MONTHSUM");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            thisYear.add(yearsum1);
        }
        for (int i = 0; i < month; i++) {
            Object monthsum = ssgqList.get(i).get("SNTY");
            int yearsum1 = (int) (Double.parseDouble(monthsum.toString()) * 10000);
            lastYear.add(yearsum1);
        }
        cyxt.setDataItem2(thisYear.toString().replace(" ", ""));
        cyxt.setDataItem3(lastYear.toString().replace(" ", ""));
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
    }

    /**
     * Methad info:,洋山深水港吞吐总量占比月趋势
     *
     * @author 陈兆庆
     * @date 2022/1/5 10:51
     */
    public static void buildTotalThroughputMonthlyTrendofpProportion(int month, List<Map<String, Object>> ssgqList, List<Map<String, Object>> containerList, List list) {
        Cyxt cyxt = buildgeneralpParame("481383e695394c50827badbc8efe4d9d", "hyLazy", "myChart20");
        cyxt.setDataItem1(buildMonth(month).toString().replace(" ", ""));
        ArrayList<String> dataList = new ArrayList<>();
        for (int i = 0; i < month; i++) {
            //公式：（洋山深水港区月完成量除以集装箱月吞吐量乘以100）
            Object monthsunssgq = ssgqList.get(i).get("MONTHSUM");//深水港
            Object monthsunjzx = containerList.get(i).get("MONTHSUM");//集装箱
            double data = (Double.parseDouble(monthsunssgq.toString()) / Double.parseDouble(monthsunjzx.toString())) * 100;
            String result = String.format("%.2f", data);
            dataList.add(result);
        }
        cyxt.setDataItem2(dataList.toString().replace(" ", ""));
        String data = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(data);
    }


    /**
     * Methad info:通用的参数
     *
     * @return com.wonders.cyxtjsonupdate.entity.Cyxt
     * @author 陈兆庆
     * @date 2022/1/4 14:47
     */
    public static Cyxt buildgeneralpParame(String id, String mainType, String subType) {
        Cyxt cyxt = new Cyxt();
        cyxt.setId(id);
        cyxt.setMainType(mainType);
        cyxt.setSubType(subType);
        return cyxt;
    }

    /**
     * Methad info:拼接月份
     *
     * @author 陈兆庆
     * @date 2022/1/4 16:14
     */
    public static List buildMonth(int month) {
        ArrayList<String> monthList = new ArrayList<>();
        //拼接月份
        for (int i = 0; i < month; i++) {
            if (i == 0) {
                monthList.add("'1月'");
            } else if (i == 1) {
                monthList.add("'2月'");
            } else if (i == 2) {
                monthList.add("'3月'");
            } else if (i == 3) {
                monthList.add("'4月'");
            } else if (i == 4) {
                monthList.add("'5月'");
            } else if (i == 5) {
                monthList.add("'6月'");
            } else if (i == 6) {
                monthList.add("'7月'");
            } else if (i == 7) {
                monthList.add("'8月'");
            } else if (i == 8) {
                monthList.add("'9月'");
            } else if (i == 9) {
                monthList.add("'10月'");
            } else if (i == 10) {
                monthList.add("'11月'");
            } else if (i == 11) {
                monthList.add("'12月'");
            }
        }
        return monthList;
    }

    public static void main(String[] args) {
        CyxtJsonUtil cyxtJsonUtil = new CyxtJsonUtil();
        List list = cyxtJsonUtil.test1();
        System.out.println(list);
    }
}
